package com.chushouya.manager.service.api.impl;

import com.chushouya.common.support.Contexts;
import com.chushouya.manager.dao.entity.ActivityLogEntity;
import com.chushouya.manager.dao.repository.ActivityLogRepository;
import com.chushouya.manager.dto.admin.activity.ActivityLogQuery;
import com.chushouya.manager.service.api.ActivityLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class ActivityLogServiceImpl implements ActivityLogService {
    @Resource
    private ActivityLogRepository activityLogRepository;
    @Override
    public void addActivityLog(Long activityId, String activityName, String activityPrize,Integer activityType, String platform, String appId) {
        final Long userId = Contexts.getUserContext().getUserId();
        ActivityLogEntity activityLogEntity = new ActivityLogEntity();
        activityLogEntity.setActivityId(activityId);
        activityLogEntity.setActivityName(activityName);
        activityLogEntity.setActivityPrize(activityPrize);
        activityLogEntity.setUserId(userId);
        activityLogEntity.setActivityType(activityType);
        activityLogEntity.setPlatform(platform);
        activityLogEntity.setAppId(appId);
        activityLogRepository.insertSelective(activityLogEntity);
    }

    @Override
    public boolean isJoinActivity(Long activityId,Long userId) {
        final String appId = Contexts.getHeaderContext().getAppId();
        ActivityLogQuery query = new ActivityLogQuery();
        query.setActivityId(activityId);
        query.setUserId(userId);
        query.setAppId(appId);
        ActivityLogEntity activityLogEntity = activityLogRepository.selectOne(query);
        return Objects.nonNull(activityLogEntity);
    }
}
